class CombinationIterator:

    def __init__(self, characters: str, combinationLength: int):
        self.characters = characters
        self.combinationLength = combinationLength
        self.index = list(range(combinationLength))
        self.index[-1] -= 1
    
    def _index_add(self, depth=-1):
        self.index[depth] += 1
        if self.index[depth] > len(self.characters) + depth:
            next_start = self._index_add(depth - 1) + 1
            self.index[depth] = next_start
        return self.index[depth]


    def next(self) -> str:
        self._index_add()
        return ''.join([self.characters[i] for i in self.index])


    def hasNext(self) -> bool:
        for n, i in enumerate(self.index):
            if i != len(self.characters) - (self.combinationLength - n):
                return True
        return False



# Your CombinationIterator object will be instantiated and called as such:
if __name__ == '__main__':
    obj = CombinationIterator("abcd", 3)
    print(obj.next())
    print(obj.hasNext())
    print(obj.next())
    print(obj.hasNext())
    print(obj.next())
    print(obj.hasNext())
    print(obj.next())
    print(obj.hasNext())
